package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	
	public class PanelDateCenter extends JPanel
	{
		//members define
		private var labelDateName:JLabel;
		private var labelDateTimer:JLabel;
		private var labelDateStep:JLabel;
		private var labelStealLove:JLabel;
		private var labelCare:JLabel;
		public function PanelDateCenter()
		{
			//component creation
			setEnabled(false);
			setSize(new IntDimension(380, 422));
			setPreferredSize(new IntDimension(380, 422));
			setConstraints("Center");
			var layout0:SoftBoxLayout = new SoftBoxLayout();
			layout0.setAxis(AsWingConstants.VERTICAL);
			layout0.setAlign(AsWingConstants.TOP);
			layout0.setGap(0);
			setLayout(layout0);
			
			labelDateName = new JLabel();
			labelDateName.setLocation(new IntPoint(5, 5));
			labelDateName.setSize(new IntDimension(26, 17));
			labelDateName.setPreferredSize(new IntDimension(380, 24));
			labelDateName.setText("label");
			
			labelDateTimer = new JLabel();
			labelDateTimer.setLocation(new IntPoint(0, 24));
			labelDateTimer.setSize(new IntDimension(380, 17));
			labelDateTimer.setPreferredSize(new IntDimension(380, 24));
			labelDateTimer.setText("label");
			
			labelDateStep = new JLabel();
			labelDateStep.setLocation(new IntPoint(0, 48));
			labelDateStep.setSize(new IntDimension(380, 17));
			labelDateStep.setPreferredSize(new IntDimension(380, 17));
			labelDateStep.setText("label");
			
			labelStealLove = new JLabel();
			labelStealLove.setLocation(new IntPoint(0, 51));
			labelStealLove.setSize(new IntDimension(380, 17));
			labelStealLove.setPreferredSize(new IntDimension(380, 17));
			labelStealLove.setText("label");
			
			labelCare = new JLabel();
			labelCare.setLocation(new IntPoint(0, 68));
			labelCare.setSize(new IntDimension(380, 17));
			labelCare.setPreferredSize(new IntDimension(380, 17));
			labelCare.setText("label");
			
			//component layoution
			append(labelDateName);
			append(labelDateTimer);
			append(labelDateStep);
			append(labelStealLove);
			append(labelCare);
			
			//----------------------------------
			setImages();
			
		}
		public function setImages():void
		{
			setConstraints("Center");
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelDateName.setForeground(ASColor.RED);
			labelDateName.setFont(new ASFont("宋体", 14, true, false, false, false));
			labelDateName.setTextFilters( new Array(filter));
			
			labelDateTimer.setForeground(ASColor.ORANGE);
			labelDateTimer.setFont(new ASFont("宋体", 13, false, false, false, false));
			labelDateTimer.setTextFilters( new Array(filter));
			
			labelDateStep.setForeground(ASColor.GREEN);
			labelDateStep.setFont(new ASFont("宋体", 13, false, false, false, false));
			labelDateStep.setTextFilters( new Array(filter));
			
			labelStealLove.setForeground(ASColor.WHITE);
			labelStealLove.setFont(font);
			labelStealLove.setTextFilters( new Array(filter));
			
			labelCare.setForeground(ASColor.WHITE);
			labelCare.setFont(font);
			labelCare.setTextFilters( new Array(filter));
		}
		private var _object:Object = null
		public function setData(object:Object):void
		{
			_object = object;
			var objDateCSV:Object = Client.getInstance().GetDateCSV(object.m_nDateCSVId);
			labelDateName.setText("");
			labelDateTimer.setText("");
			labelDateStep.setText("");
			labelStealLove.setText("");
			labelCare.setText("");
			if(object.m_nDateCharId == 0)
			{
				labelDateName.setText("你还没有约会,可通过配对或与好友约会");
				labelDateStep.setText("偷窥约会和被约会都能得到丰富奖励");
				labelStealLove.setText("可与离线好友约会,也可偷窥离线好友");
				return;
			}
			labelDateName.setText(object.m_szSelfCharName+"和"+object.m_szDateCharName+"的约会");
			
			labelDateStep.setText("进度:"+object.m_nDateStep+'/'+objDateCSV.step_size+','+"调情:"+object.m_nDateStealLoveCount+'/3'+','+
				"电灯泡:"+object.m_nDateFriendCareCount+'/3');
			//labelStealLove.setText("调情:"+object.m_nDateStealLoveCount+'/3');
			//labelCare.setText("电灯泡:"+object.m_nDateFriendCareCount+'/3');
			
			var nMoney:int = 0;
			var nStep:int = _object.m_nDateStep;
			while (nStep > 0)
			{
				nMoney += objDateCSV.step_money * nStep;
				nStep--;
			}
			
			var nEXP:int = 0;
			nStep = _object.m_nDateStep;
			while (nStep > 0)
			{
				nEXP += objDateCSV.step_exp * nStep;
				nStep--;
			}
			
			labelStealLove.setText("预计当前收益:经验+"+nEXP+",铜币+"+nMoney);
			
			if(_object.m_nDateStep < objDateCSV.step_size)
			{

				nMoney = 0;
				nStep = _object.m_nDateStep + 1;
				while (nStep > 0)
				{
					nMoney += objDateCSV.step_money * nStep;
					nStep--;
				}
				nStep = _object.m_nDateStep + 1;
				nEXP = 0;
				while (nStep > 0)
				{
					nEXP += objDateCSV.step_exp * nStep;
					nStep--;
				}
				
				//labelCare.setText("下一进度收益:铜币+"+nMoney);
				labelCare.setText("下一进度收益:经验+"+nEXP+",铜币+"+nMoney);
			}
			
			PanelDateCenter.update();
			
			
		}
		
		
		
		private static var _instance:* = null;
		public static function getInstance():PanelDateCenter
		{
			if(_instance == null)
				_instance = new PanelDateCenter();
			return _instance;
		}
		public static function update():void
		{
			
			if(getInstance()._object != null && getInstance()._object.m_nDateCharId != 0)
			{
				var objDateCSV:Object = Client.getInstance().GetDateCSV(_instance._object.m_nDateCSVId);
				if(objDateCSV == null)
					return;
				if(_instance._object.m_nDateStartTime < objDateCSV.step_interval)
				{
					_instance._object.m_nDateStartTime++;
					if(_instance._object.m_nDateStartTime == objDateCSV.step_interval)
					{
						PanelDate.getInstance().update();
					}
				}
				
				if(PanelDate._isInDate)
				{
					if(_instance._object.m_nDateStartTime < objDateCSV.step_interval)
					{
						_instance.labelDateTimer.setText(PanelMainHelp.formatTime(objDateCSV.step_interval-_instance._object.m_nDateStartTime));
					}
					else
					{
						if(_instance._object.m_nDateStep >= objDateCSV.step_size)//进度完成
						{
						
							if(_instance._object.m_nDateFriendCareCount >= 3)
							{
								_instance.labelDateTimer.setText("约会已完成,等待主人结束约会获得收益!");
								return;
							}
						}
						
						_instance.labelDateTimer.setText("需要好友来当电灯泡才能提升进度!");
					}
					_instance.pack();
				}
				
			}
		}
	}
}